using System;

namespace Kangaroo.Deferreds
{
    public interface IDeferred<T>
    {
        DeferredState State { get; }
        IDeferred<T> OnDone(params Action<T>[] doneCallbacks);
        void Resolve(T result);
        IDeferred<T> OnFail(params Action<Exception>[] failCallbacks);
        void Reject(Exception exception);
        IDeferred<T> Then(Action<T> doneCallback, Action<Exception> failCallback = null);

        IDeferred<TResult> Pipe<TResult>(
            Func<T, TResult> doneTransform,
            Func<Exception, Exception> failTransform = null);

        IDeferred<TResult> Chain<TResult>(
            Func<T, IDeferred<TResult>> doneChain, 
            Func<Exception, IDeferred<TResult>> failChain = null);

        IDeferred<T> Promise();
    }
}